package cn.cvs.utils;

import sun.security.krb5.Config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 通过单例模式读取配置
 */
public class ConfigManager {
    private static Properties properties;
    private static ConfigManager configManager=new ConfigManager();

    /**
     * 杜绝创建该类对象，私有构造方法
     */
    public ConfigManager() {
        String configFile="database.properties";
        properties = new Properties();
        InputStream is = ConfigManager.class.getClassLoader().getResourceAsStream(configFile);
        try {
            properties.load(is);
            is.close();
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }

    /**
     * 对外提取ConfigManager实例方法
     */
//    public static synchronized ConfigManager getInstance(){
//        if (configManager==null) {
//            configManager=new ConfigManager();
//        }
//        return configManager;
//    }

    /**
     * 饿汉模式
     */
    public static ConfigManager getInstance(){
        return configManager;
    }

    /**
     * 读取配置文件信息
     */
    public String getValue(String key){
        return properties.getProperty(key);
    }
}
